package com.rc.saas.mini.hlhtcec2.printer;

import com.rc.saas.mini.model.hlhtsk.HlhtskBizOperator;
import com.rc.saas.mini.model.hlhtsk.HlhtskBizTenant;
import com.rc.saas.mini.vo.hlhtcec2.TokenResult;
import com.rc.saas.mini.vo.printer.QueryPrintReq;
import com.rc.saas.mini.vo.printer.QueryPrintResult;
import com.rc.saas.mini.vo.printer.StartPrintReq;
import com.rc.saas.mini.vo.printer.StartPrintResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

/**
 * @author wangzhengwei
 * @create 2021/4/23
 */
@Component
public class HlhtPrinterAssemble {
    private static Logger logger = LogManager.getLogger(HlhtPrinterAssemble.class);

    /**
     * 通过订单号查找是否有打印机
     */
    public QueryPrintResult assembleNotifyQueryPrintResult(QueryPrintReq queryPrintReq, TokenResult tokenResult,
                                                           HlhtskBizOperator bizOperator, HlhtskBizTenant bizTenant) {
        //根据运营商operatorID找出对应的API
        HlhtPrintStrategy strategy = HlhtPrinterStrategyFactory.getInstance().get(bizOperator.getHlhtOperatorId());
        if (strategy == null) {
            //throw new IllegalArgumentException("please input right type");
            logger.warn("还没开通打印机接口");
            return null;
        }

        return strategy.query_print(queryPrintReq, tokenResult, bizOperator, bizTenant);
    }

    /**
     * 开始打印
     */
    public StartPrintResult assembleNotifyQueryStartPrintResult(StartPrintReq queryPrintReq, TokenResult tokenResult,
                                                                HlhtskBizOperator bizOperator, HlhtskBizTenant bizTenant) {
        //根据运营商operatorID找出对应的API
        HlhtPrintStrategy strategy = HlhtPrinterStrategyFactory.getInstance().get(bizOperator.getHlhtOperatorId());
        if (strategy == null) {
            //throw new IllegalArgumentException("please input right type");
            logger.warn("还没开通打印机接口");
            return null;
        }

        return strategy.query_start_print(queryPrintReq, tokenResult, bizOperator, bizTenant);
    }
}
